<?php  

/** 
* Members Page (Controller) 
* Страница участников (контроллер) 
* @author IT studio IRBIS-team 
* @copyright © 2009 IRBIS-team 
*/
/////////////////////////////////////////////////////////

/**
* Generation of page of an error at access out of system
* Генерация страницы ошибки при доступе вне системы
*/
    if(!defined('IRB_KEY'))
    {
       header("HTTP/1.1 404 Not Found");      
       exit(file_get_contents('../../404.html'));
    } 
//////////////////////////////////////////////////////////

/**
* We connect a file of the MySQL functions
* Подключаем файл функций MySQL
*/  
   include './libs/mysql.php'; 

	$domains = mysqlQuery("SELECT 	dlu.domain_id as d_id,
									d.caption as d_caption 
							
							FROM 	`soc_dom_link_user` dlu,
									`soc_domains` d
							
							WHERE dlu.user_id=".(int)$_SESSION['user_data']['id']."
							
							AND dlu.domain_id = d.id");
	
	if(mysql_num_rows($domains) > 0)
	{
		while($d = mysql_fetch_assoc($domains))
		{
			$users_query =  mysqlQuery("SELECT u.id as u_id,
												u.login as u_login,
												u.name as u_name,
												u.surname as u_surname
										
										FROM 	soc_user u,
												soc_dom_link_user dlu
										
										WHERE dlu.domain_id = ".$d['d_id']."										
										AND dlu.user_id = u.id
										");
			
			if(mysql_num_rows($users_query) > 0)
			{
				$users = array();
				while($row = mysql_fetch_assoc($users_query))
				{
					$users[] = array(
										'u_id' => $row['u_id'],
										'u_caption' => (empty($row['u_surname']) AND empty($row['u_name']))?$row['u_login']:$row['u_surname']." ".$row['u_name']
									);
				}
			}	
			
			$d_array[] = array(
								'd_id' => $d['d_id'],
								'd_caption' => $d['d_caption'],
								'users'	=> $users
								);
		}
	}

     
	

